package com.lqz.tools;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.*;

public class JDBCTest {
	public static void main(String[] args) throws Exception {
		// 1.加载驱动
		// Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
		// Class.forName("com.mysql.jdbc.Driver");
		//Class.forName("oracle.jdbc.driver.OracleDriver");
		//1.加载驱动
		   //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"	); 
		   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
		// 2.创建数据库连接对�?
		 //Connection conn =
		 //DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=db","sa","sqlpass");
		 Connection conn=DriverManager.getConnection("jdbc:odbc:DB_DR","luo","123456");
		 // Connection conn =
		// DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=UTF-8","root","123456");
		//Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "Oracle123");

		// 3.创建数据库命令执行对�?
		Statement stmt = conn.createStatement();
		// PreparedStatement ps = conn.prepareStatement("select * from t_user");

		// 4.执行数据库命�?
		stmt.executeUpdate("insert into test values('woasd','19','230.4')");
		ResultSet rs = stmt.executeQuery("select * from test");
		// ResultSet rs = ps.executeQuery();

		// 5.处理执行结果
		while (rs.next()) {
			//int id = rs.getInt("id");
			String username = rs.getString("name");
			String password = rs.getString("age");
			String h = rs.getString("height");
			System.out.println(h + "\t" + username + "\t" + password);
		}

		// 6.释放数据库资�?
		if (rs != null) {
			rs.close();
		}
		// if (ps != null) {
		// ps.close();
		// }
		if (stmt != null) {
			stmt.close();
		}
		if (conn != null) {
			conn.close();
		}
	}
}